package edu.zjut.hjg.saas.biz.dao.impl;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.springframework.orm.ibatis.support.SqlMapClientDaoSupport;

import edu.zjut.hjg.saas.biz.dao.SchoolClassDao;
import edu.zjut.hjg.saas.biz.model.SchoolClass;

public class SchoolClassDaoImpl extends SqlMapClientDaoSupport implements SchoolClassDao {

    @Override
    public Integer create(SchoolClass schoolClass) {
        return (Integer) getSqlMapClientTemplate().insert("schoolClass.create", schoolClass);
    }

    @SuppressWarnings("unchecked")
    @Override
    public List<SchoolClass> listByAppId(int appId) {
        return getSqlMapClientTemplate().queryForList("schoolClass.listByAppId", appId);
    }

    @Override
    public SchoolClass load(int id) {
        return (SchoolClass) getSqlMapClientTemplate().queryForObject("schoolClass.load", id);
    }

    @Override
    public void update(SchoolClass schoolClass) {
        getSqlMapClientTemplate().update("schoolClass.update", schoolClass);
    }

    @Override
    public void deleteByIdAndAppId(int id, int appId) {
        Map<String, Object> params = new HashMap<String, Object>();
        params.put("id", id);
        params.put("appId", appId);
        getSqlMapClientTemplate().delete("schoolClass.deleteByIdAndAppId", params);
    }

    @Override
    public SchoolClass findByIdAndAppId(int id, int appId) {
        Map<String, Object> params = new HashMap<String, Object>();
        params.put("id", id);
        params.put("appId", appId);
        return (SchoolClass) getSqlMapClientTemplate().queryForObject(
                "schoolClass.findByIdAndAppId", params);
    }
}
